package com.example.demo.controller;
import com.example.demo.dao.PersonRepository;
import com.example.demo.model.userTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by zouwenchang on 2018/1/26.
 */
@RestController
public class userController {
    @Autowired
    PersonRepository personRepository;
    @CrossOrigin(origins = "*", allowedHeaders = "*", allowCredentials = "true")
    @GetMapping(value = "/person")
    private List<userTable> personList() {
        return personRepository.findAll();
    }
    @CrossOrigin(origins = "*", allowedHeaders = "*", allowCredentials = "true")
    @PostMapping(value = "/addPerson")
    private userTable addPerson(@RequestParam("id") Integer id,
                                @RequestParam("email") String email,
                                @RequestParam("nick") String nick,
                                @RequestParam("pwd") String pwd,
                                @RequestParam("names") String names
                                ) {
        userTable users=new userTable();

        users.setEmail(email);
        users.setId(id);
        users.setNickName(nick);
        users.setUserName(names);
        users.setPassword(pwd);

        return personRepository.save(users);

    }
}
